package frontend.user.controller;

import java.sql.Date;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import core.address.model.BasicAddress;
import core.profile.model.BasicProfile;
import core.profile.model.BasicProfileAv;
import frontend.user.dao.EditProfileDao;

public class TravellerProfile extends ActionSupport {
		
		private static final long serialVersionUID = -4008768000656606508L;
		private String firstname;
		private String lastname;
		private String mobile;
		private String companyname;
		private String college;
		private String addressLine1;
		private String addressLine2;
		private String gender;
		private String language;
		private Date creationdate;
		private Long uuid ;
		private BasicProfile basicProfile;
		private BasicProfile basicProfile1;
		private BasicAddress basicAddress;
		private BasicProfileAv basicProfileAv;
		
		public String getFirstname() {
			return firstname;
		}
		public void setFirstname(String firstname) {
			this.firstname = firstname;
		}
		public String getLastname() {
			return lastname;
		}
		public void setLastname(String lastname) {
			this.lastname = lastname;
		}
		public String getMobile() {
			return mobile;
		}
		public void setMobile(String mobile) {
			this.mobile = mobile;
		}
		public String getCompanyname() {
			return companyname;
		}
		public void setCompanyname(String companyname) {
			this.companyname = companyname;
		}
		/**
		 * @return the college
		 */
		public String getCollege() {
			return college;
		}
		/**
		 * @param college the college to set
		 */
		public void setCollege(String college) {
			this.college = college;
		}
		
		/**
		 * @return the addressLine1
		 */
		public String getAddressLine1() {
			return addressLine1;
		}
		/**
		 * @param addressLine1 the addressLine1 to set
		 */
		public void setAddressLine1(String addressLine1) {
			this.addressLine1 = addressLine1;
		}
		/**
		 * @return the addressLine2
		 */
		public String getAddressLine2() {
			return addressLine2;
		}
		/**
		 * @param addressLine2 the addressLine2 to set
		 */
		public void setAddressLine2(String addressLine2) {
			this.addressLine2 = addressLine2;
		}
		/**
		 * @return the gender
		 */
		public String getGender() {
			return gender;
		}
		/**
		 * @param gender the gender to set
		 */
		public void setGender(String gender) {
			this.gender = gender;
		}
		/**
		 * @return the language
		 */
		public String getLanguage() {
			return language;
		}
		/**
		 * @param language the language to set
		 */
		public void setLanguage(String language) {
			this.language = language;
		}
		/**
		 * @return the creationdate
		 */
		public Date getCreationdate() {
			return creationdate;
		}
		/**
		 * @param creationdate the creationdate to set
		 */
		public void setCreationdate(Date creationdate) {
			this.creationdate = creationdate;
		}
		public Long getUuid() {
			return uuid;
		}
		public void setUuid(Long uuid) {
			this.uuid = uuid;
		}
		public BasicProfile getBasicProfile() {
			return basicProfile;
		}
		public void setBasicProfile(BasicProfile basicProfile) {
			this.basicProfile = basicProfile;
		}
		public BasicAddress getBasicAddress() {
			return basicAddress;
		}
		public void setBasicAddress(BasicAddress basicAddress) {
			this.basicAddress = basicAddress;
		}
		public BasicProfileAv getBasicProfileAv() {
			return basicProfileAv;
		}
		public void setBasicProfileAv(BasicProfileAv basicProfileAv) {
			this.basicProfileAv = basicProfileAv;
		}
		
		public String  execute() throws Exception{
			
			Map<String, Object> session = ActionContext.getContext().getSession();
			if(session.get("uuid")!=null){
			basicProfile=GetDataByEmailId.listProfileById((Long) session.get("uuid"));
			//basicAddress=GetDataByEmailId.getBasicAddressByEmailId(session.get("emailId").toString());
			return SUCCESS;
			}
			else{
				return ERROR;
			}
			
		}
		
		public String updateProfile(){
			Map<String, Object> session = ActionContext.getContext().getSession();
			if(session.get("uuid")!=null){
			basicProfile1=GetDataByEmailId.listProfileById((Long) session.get("uuid"));
			BasicAddress currentAddress = this.getBasicProfile().getCurrentAddress();
			if(currentAddress == null)
			{
				currentAddress = new BasicAddress();
			}
			currentAddress.setAddressLine1(this.getAddressLine1());
			currentAddress.setAddressLine2(this.getAddressLine2());
			basicProfile1.setFirstname(this.basicProfile.getFirstname());
			basicProfile1.setLastname(this.basicProfile.getLastname());
			basicProfile1.setAboutus(this.basicProfile.getAboutus());
			basicProfile1.setCompanyname(this.basicProfile.getCompanyname());
			basicProfile1.setCollege(this.basicProfile.getCollege());
			basicProfile1.setGender(this.basicProfile.getGender());
			basicProfile1.setLanguage(this.basicProfile.getLanguage());
			basicProfile1.setCurrentAddress(currentAddress);
			EditProfileDao.saveAddress(currentAddress);
			EditProfileDao.editProfile(basicProfile1);
			
			return SUCCESS;
			}
			else{
				return ERROR;
			}
		}

	}


